<div class="tmd-doc">
<p></p>
<h1 class="tmd-header-1">
reflect 2
</h1>
<p></p>
<div id="question" class="tmd-base">
<p></p>
<div class="tmd-usual">
What does the following program print?
</div>
<p></p>
<pre class="tmd-code line-numbers">
<code class="language-go">package main

import "reflect"

type T struct{
  A int
  b int
}

func (T) M() {}
func (T) m() {}

func main() {
	v := reflect.ValueOf(T{})
	println(v.NumField(), v.NumMethod())
}
</code></pre>
</div>
<p></p>
<div class="tmd-usual">
Choices:
</div>
<p></p>
<input type="radio" id="choiceA" name="choice" class="choice">
<input type="radio" id="choiceB" name="choice" class="choice">
<input type="radio" id="choiceC" name="choice" class="choice">
<input type="radio" id="choiceD" name="choice" class="choice">

<div id="choices">

<ul style="list-style-type:none;">
<li><label for="choiceA">1 1</label></li>
<li><label for="choiceB">1 2</label></li>
<li><label for="choiceC">2 1</label></li>
<li><label for="choiceD">2 2</label></li>
</ul>

</div><p></p>
<div id="answer" class="tmd-base">
<div class="tmd-usual">
Answer: 2 1
</div>
<p></p>
<div class="tmd-usual">
Run it on <a href="https://go.dev/play/p/bvWfO-zkRxF">Go play</a>.
</div>
<p></p>
<div class="tmd-usual">
Key point:
</div>
<ul class="tmd-list">
<li class="tmd-list-item">
<div class="tmd-usual">
the <code class="tmd-code-span">reflect.Value.NumMethod</code> method only counts exported methods for non-interface types/values.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
the <code class="tmd-code-span">reflect.Value.NumField</code> method counts both exported and unexported fields.
</div>
</li>
</ul>
<p></p>
</div>
<p></p>
</div>
